package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 *
 * @author 刘阳
 * @date 2019/4/4 3:48 PM
 * @since v1.0
 * @version v1.0
 */
public enum WorkOrderEmergencyEnum {
    /*

     */

    NORMAL(0,"normal","enum.workOrderEmergency.name.normal"),
    EMERGENCY(1,"emergency","enum.workOrderEmergency.name.emergency"),
    VARY_EMERGENCY(2,"vary_emergency","enum.workOrderEmergency.name.vary_emergency"),
    ;

    //枚举值
    private int code;
    //控件的英文描述
    private String alias;
    //中文描述
    private String name;

    WorkOrderEmergencyEnum(int code,String alias,String name){
        this.code = code;
        this.alias = alias;
        this.name = name;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getAlias() {
        return alias;
    }

    public void setAlias(String alias) {
        this.alias = alias;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取全部枚举
     *
     * @return List<WorkOrderEmergencyEnum>
     */
    public static List<WorkOrderEmergencyEnum> getAllEnum() {
        List<WorkOrderEmergencyEnum> list = new ArrayList<WorkOrderEmergencyEnum>();
        for (WorkOrderEmergencyEnum cache : values()) {
            list.add(cache);
        }
        return list;
    }

    public static WorkOrderEmergencyEnum getByCode(Integer code) {
        for (WorkOrderEmergencyEnum emergencyEnum : values()) {
            if (Objects.equals(emergencyEnum.getCode(), code)) {
                return emergencyEnum;
            }
        }
        return null;
    }

    public static Integer getByName(String name) {
        for (WorkOrderEmergencyEnum emergencyEnum : values()) {
            if (Objects.equals(emergencyEnum.getName(), name)) {
                return emergencyEnum.getCode();
            }
        }
        return null;
    }
}
